﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SampleDataTools
{
    public partial class LightDisplayArea : UserControl
    {
        public LightDisplayArea()
        {
            InitializeComponent();
            lightButton.StatusColors = new Color[] { Color.Gray, Color.Green };
        }

        private ThresholdValueItemConfig valueItemConfig;

        public void SetConfig(ThresholdValueItemConfig config)
        {
            valueItemConfig = config;
            label1.Text = config.Name;
        }

        public void Update(BuffData[] datas)
        {
            if (datas != null && datas.Length > valueItemConfig.DataIndex)
            {
                var data = datas[valueItemConfig.DataIndex];
                if (data != null)
                {
                    textBox1.Text = data.GetValueFormmat(valueItemConfig.Index);
                    var value = data.GetValue(valueItemConfig.Index);
                    if (value > valueItemConfig.Threshold)
                    {
                        lightButton.CurrentStatus = 1;
                    }
                    else
                    {
                        lightButton.CurrentStatus = 2;
                    }
                    lightButton.Refresh();
                }
            }
        }
    }
}
